from django.db import models

class SystemAdmin(models.Model):
    username = models.CharField(verbose_name='用户名', max_length=30, db_index=True)
    password = models.CharField(verbose_name='密码', max_length=88)
    name = models.CharField(verbose_name='名称', max_length=20, null=True, blank=True)
    pid = models.IntegerField(verbose_name='添加者id', default=0)
    role = models.ForeignKey(verbose_name="权限id", to="Roles", on_delete=models.SET_NULL, null=True, blank=True)
    scope_choices = ((8, "普通用户"), (16, "商户"), (32, "管理员"))  
    scope = models.SmallIntegerField(verbose_name="权限值", choices=scope_choices, null=True, default=8)
    active_choices = ((0, "关闭"), (1, "开启"))
    is_active = models.SmallIntegerField(verbose_name="是否开启", choices=active_choices, db_index=True, default=1)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    class Meta:
        db_table = "system_admin"
        verbose_name = '管理员列表'

class Menus(models.Model):
    pid = models.SmallIntegerField(verbose_name='上级id', default=0)
    icon = models.CharField(verbose_name='图标', max_length=20)
    menu_name = models.CharField(verbose_name='菜单名称', max_length=33, db_index=True)
    path_name = models.CharField(verbose_name='路由名称', max_length=33, null=True, blank=True)
    path = models.CharField(verbose_name='路径', max_length=33, null=True, blank=True)
    sort = models.SmallIntegerField(verbose_name="排序", default=100)
    active_choices = ((0, "关闭"), (1, "开启"))
    is_active = models.SmallIntegerField(verbose_name="是否开启", choices=active_choices, db_index=True, default=1)

    class Meta:
        db_table = "system_menus"
        verbose_name = '导航菜单'

class Roles(models.Model):
    role_name = models.CharField(verbose_name="权限名称", max_length=33)
    user_id = models.IntegerField(verbose_name="添加者id", default=1)
    active_choices = ((0, "关闭"), (1, "开启"))
    is_active = models.SmallIntegerField(verbose_name="是否开启", choices=active_choices, db_index=True, default=1)
    
    menus = models.ManyToManyField(verbose_name="菜单id", to="Menus")

    class Meta:
        db_table = "system_roles"
        verbose_name = '权限列表'      

# class SystemRolesMenus(models.Model):
#     role = models.ForeignKey(verbose_name="权限id", to="SystemRoles", on_delete=models.CASCADE)
#     menu = models.ForeignKey(verbose_name="菜单id", to="SystemMenus", on_delete=models.CASCADE)

#     class Meta:
#         db_table = "system_roles_menus"
#         verbose_name = '导航菜单权限关联表' 